package cn.itsub.sodo.action.interval;

import cn.itsub.sodo.Node;
import cn.itsub.sodo.action.base.FiniteTimeAction;


/**
 * 间隔动作，在一段时间内完成
*/
public class IntervalAction extends FiniteTimeAction {
	/** 已经运行了多久 */
    protected float elapsed;
	private boolean firstTick;	

    public float getElapsed() {
        return elapsed;
    }
    
    public static IntervalAction action(float duration) {
    	return new IntervalAction(duration);
    }

    protected IntervalAction(float d) {    	
        super(d);
        if (duration == 0)
    		duration = 0.000001f;
        elapsed = 0.0f;
        firstTick = true;
    }

    @Override
    public IntervalAction copy() {
        return new IntervalAction(duration);
    }

    public boolean isDone() {
        return (elapsed >= duration);
    }

    @Override
    public void step(float dt) {
        if (firstTick) {
            firstTick = false;
            elapsed = 0;
        } else{
        	elapsed += dt;
        }
        update(Math.min(1, elapsed / duration));
    }

    @Override
    public void start(Node aTarget) {
        super.start(aTarget);
        elapsed = 0.0f;
        firstTick = true;
    }

    public void setAmplitudeRate(float amp) {
    	
    }

    public float getAmplitudeRate() {
    	
    	return 0;
    }
}
